It shows how to enumerate one or more frame grabbers via enumeration APIs and perform operations such as turning on frame grabbers and setting attributes.
11 currentsystem = platform.system()
12 if currentsystem ==
'Windows':
13 sys.path.append(os.path.join(os.getenv(
'MVCAM_COMMON_RUNENV'),
"Samples",
"Python",
"MvImport"))
15 sys.path.append(os.path.join(
"..",
"..",
"MvImport"))
17 from MvCameraControl_class
import *
21 if sys.version_info[0] < 3:
23 input_func = raw_input
31 Safely decode a string from a ctypes character array. 32 Compatible with Python 2.x and 3.x, as well as 32-bit and 64-bit environments. 34 byte_str = memoryview(ctypes_char_array).tobytes()
37 null_index = byte_str.find(b
'\x00')
39 byte_str = byte_str[:null_index]
42 for encoding
in [
'gbk',
'utf-8',
'latin-1']:
44 return byte_str.decode(encoding)
45 except UnicodeDecodeError:
49 return byte_str.decode(
'latin-1', errors=
'replace')
52 if __name__ ==
"__main__":
56 MvCamera.MV_CC_Initialize()
58 SDKVersion = MvCamera.MV_CC_GetSDKVersion()
59 print (
"SDKVersion[0x%x]" % SDKVersion)
61 interfaceList = MV_INTERFACE_INFO_LIST()
62 transportLayerType = MV_GIGE_INTERFACE | MV_CAMERALINK_INTERFACE | MV_CXP_INTERFACE | MV_XOF_INTERFACE
65 ret = MvCamera.MV_CC_EnumInterfaces(transportLayerType, interfaceList)
67 print(
"enum interfaces fail! ret[0x%x]" % ret)
70 if interfaceList.nInterfaceNum == 0:
71 print(
"find no interface!")
74 print(
"Find %d interfaces!" % interfaceList.nInterfaceNum)
76 for i
in range(0, interfaceList.nInterfaceNum):
77 interfaceInfo = cast(interfaceList.pInterfaceInfos[i], POINTER(MV_INTERFACE_INFO)).contents
78 print(
"interface: [%d]" % i)
81 print(
"display name: %s" % displayName)
84 print(
"serial number: %s" % serialNumber)
87 print(
"model name: %s" % modelName)
90 print(
"interface id: %s" % interfaceId)
92 nConnectionNum =
input_func(
"please input the number of the interface to connect:")
94 if int(nConnectionNum) >= interfaceList.nInterfaceNum:
102 curInterface = cast(interfaceList.pInterfaceInfos[int(nConnectionNum)], POINTER(MV_INTERFACE_INFO)).contents
104 ret = cam.MV_CC_CreateInterface(curInterface)
106 raise Exception(
"create interface handle fail! ret[0x%x]" % ret)
108 ret = cam.MV_CC_OpenInterface()
110 raise Exception(
"open interface fail! ret[0x%x]" % ret)
112 print(
"open interface success")
115 stEnumValue = MVCC_ENUMVALUE()
116 ret =cam.MV_CC_GetEnumValue(
"StreamSelector", stEnumValue)
118 raise Exception(
"get StreamSelector fail! ret[0x%x]" % ret)
121 ret = cam.MV_CC_SetEnumValue(
"StreamSelector", stEnumValue.nCurValue)
123 raise Exception(
"set StreamSelector fail! ret[0x%x]" % ret)
125 print(
"set StreamSelector [%d] success" % stEnumValue.nCurValue)
128 ret = cam.MV_CC_CloseInterface()
130 raise Exception(
"close interface fail! ret[0x%x]" % ret)
132 print(
"close interface success")
135 cam.MV_CC_DestroyInterface()
137 except Exception
as e:
139 cam.MV_CC_CloseDevice()
140 cam.MV_CC_DestroyInterface()
143 MvCamera.MV_CC_Finalize()